

#ifndef __GAME_PLUGIN_MANAGER_H__
#define __GAME_PLUGIN_MANAGER_H__


#include <QtCore/QObject>
#include <QtCore/QHash>
#include <QtCore/QVariant>


class QPluginLoader;
class EditorPlugin;


typedef QList<QPluginLoader*> QLoaderList;

/** 
 * @class GamePluginManager
 * @brief Simply manage all plugins. Provide load, unload, iterate ect.
 */
class GamePluginManager : public QObject
{
    Q_OBJECT
    
public:
    static GamePluginManager &instance();
    
    void initialize();
    void uninitialize();
    
    void scan(const QString &path);
    void load(const QString &path);
    void unload(const QString &path);
    
    QLoaderList plugins();

    EditorPlugin *pluginInstance(const QString &name);
    EditorPlugin *pluginInstance(uint pluginID);
    
protected:
    GamePluginManager();
    ~GamePluginManager();
    
private:
    bool check(const QString &path);
    
private:
    static GamePluginManager        msInstance;
        
    QHash<QString, QVariant>        mNames;
    QHash<QString, QVariant>        mVersions;
    QHash<QString, QVariantList>    mDependencies;
    
    QHash<QString, QPluginLoader*>  mLoaders;
};


#define MODEL_EDITOR	GamePluginManager::instance().pluginInstance("Model")
#define SCENE_EDITOR	GamePluginManager::instance().pluginInstance("Scene")


#endif  /*__GAME_PLUGIN_MANAGER_H__*/
